<?php
class AutoRateConfig_ss
{

    public $betnameArr;
    public $autorateArr;
    public $table_name = "autorate_config_ss";
    public $gametype;
    public $db;
    public $tbl;
    public $user_id;

    public function AutoRateConfig_ss( $betnameArr, $autorateArr, $gametype = 1, $user_id = 0 )
    {
        $this->betnameArr = $betnameArr;
        $this->autorateArr = $autorateArr;
        $this->gametype = $gametype;
        $this->db = new DB();
        $this->user_id = $user_id;
    }

    public function checkIfAutoRate( $bettype_id )
    {
        return in_array( $bettype_id, $this->autorateArr );
    }

    public function getAutoRateAll( )
    {
        $sql = "SELECT * FROM {$this->table_name} WHERE user_id = {$this->user_id} AND gametype = {$this->gametype}";
        $result = $this->db->query( $sql );
        $reArr = array();
        while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) )
        {
            $tempIdx = 20 <= $this->gametype ? $row['bettype'] : $row['bettype']."_".$row['subid'];
            $reArr[$tempIdx] = $row;
        }
        if ( 0 < count( $reArr ) )
        {
            return $reArr;
        }
        return false;
    }

    public function updateAutoRate( $dataArr )
    {
        foreach ( $dataArr as $val )
        {
            $sql = " UPDATE {$this->table_name} SET ";
            $sql .= " money =".$val['money'];
            $sql .= ", downrate =".$val['downrate'];
            $sql .= ", uprate =".$val['uprate'];
            $sql .= ", limitrate =".$val['limitrate'];
            $sql .= ", updateTime ='".date( "Y-m-d H:i:s" )."'";
            $sql .= " WHERE user_id=".$this->user_id." AND bettype=".$val['id']." AND subid=".$val['subid']." AND typeflag =".$val['typeflag']." AND gametype = {$this->gametype}";
            $this->db->query( $sql );
        }
    }

    public function insertAutoRate( $val )
    {
        $sql = " INSERT INTO {$this->table_name} (user_id, money, downrate, uprate, limitrate, updateTime, bettype, subid, typeflag, gametype) ";
        $sql .= " values(".$val['user_id'].", ".$val['money'].", ".$val['downrate'].", ".$val['uprate'].", ".$val['limitrate'].", '0000-00-00 00:00:00'".", ".$val['id']." , ".$val['subid']." , ".$val['typeflag']." , {$this->gametype} )";
        $this->db->query( $sql );
    }

}

?>